<template>
  <div class="IntelligentResponse">
    <div class="tableAnalysis">
      <el-table
        :data="tableDataList"
        ref="customerMgtList"
      >
        <el-table-column
          :label="item.label"
          align="center"
          v-for="(item, index) in tableColumns"
          :key="index"
          :prop="item.key"
          :min-width="item.minWidth ? item.minWidth : ``"
          :fixed="item.fixed ? item.fixed : false"
          :show-overflow-tooltip="true"
        >
          <template slot="header" v-if="item.showHeaderTip">
            <div>
              {{item.label}}
              <el-tooltip effect="dark" :content="item.showHeaderTip" placement="top">
                <span><i class="el-icon-question"></i></span>
              </el-tooltip>
            </div>
          </template>
          <!--用于表格自定义-->
          <template slot-scope="scope">
            <div>{{ scope.row[item.key] }}</div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>
<script>
import {listUser} from "@/api/system/user";
import {getTime} from "@/utils";

export default {
  name: "IntelligentResponse",
  components: {
  },
  data() {
    return {
      queryParams: {},
      timeRange: [],
      selectedRange: 'today',
      tableHeight:600,
      tableColumns: [
        {key: 'name', label: `问题名称/ID`, visible: true, minWidth: 150, fixed: true},
        {key: 'mobile', label: `所属方案/ID`, visible: true, minWidth: 150, fixed: false},
        {key: 'email', label: `所属企微号`, visible: true, minWidth: 200},
        {key: 'last_login_time', label: `问题来源`, visible: true, minWidth: 200,showHeaderTip:'问题是多号下创建并下发的，显示来源问题名称和问题ID；问题是单号下创建的，无来源问题，显示“-”；根据来源问题ID筛选，可查看该问题应用的数据汇总。',},
        {key: 'last_login_time', label: `方案来源`, visible: true, minWidth: 200,showHeaderTip:'问题是多号下创建并下发的，显示来源方案名称和方案ID；问题是单号下创建的，无来源方案，显示“-”；根据来源方案ID筛选，可查看该方案应用的数据汇总。',},
        {key: 'last_login_time', label: `Top1关键词（次数）`, visible: true, minWidth: 200,},
        {key: 'last_login_time', label: `Top2关键词（次数）`, visible: true, minWidth: 200,},
        {key: 'last_login_time', label: `Top3关键词（次数）`, visible: true, minWidth: 200,},
        {key: 'last_login_time', label: `Top4关键词（次数）`, visible: true, minWidth: 200,},
        {key: 'last_login_time', label: `Top5关键词（次数）`, visible: true, minWidth: 200,},
      ],
      tableDataList: [],
      total: 8, // 表格的总条数
    }
  },
  watch: {},
  computed: {
    dateRange() {
      const now = new Date();
      switch (this.selectedRange) {
        case 'yesterday':
          return [
            new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1),
            new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1),
          ];
        case 'today':
          return [
            now,
            new Date(now.getFullYear(), now.getMonth(), now.getDate()),
          ];
        case 'last7Days':
          return [
            new Date(now.getTime() - (6 * 24 * 60 * 60 * 1000)),
            now,
          ];
        case 'last15Days':
          return [
            new Date(now.getTime() - (14 * 24 * 60 * 60 * 1000)),
            now,
          ];
        case 'last30Days':
          return [
            new Date(now.getTime() - (29 * 24 * 60 * 60 * 1000)),
            now,
          ];
        default:
          return [];
      }
    },
  },
  created() {
    //this.getList();

  },
  methods: {
    getValue(obj){
      console.log('获取行',obj);
    },
    getTime(type) {
      this.selectedRange = type;
      setTimeout(() => {
        console.log('时间范围', this.dateRange);
        this.timeRange = [];
        this.timeRange = [this.fiterTime(this.dateRange[0]), this.fiterTime(this.dateRange[1])];
        console.log('转化时间', this.timeRange);
      }, 0)
    },
    fiterTime(value) {
      if (!value) return '';
      const date = new Date(value);
      const year = date.getFullYear();
      const month = (date.getMonth() + 1).toString().padStart(2, '0');
      const day = date.getDate().toString().padStart(2, '0');
      return `${year}-${month}-${day}`;
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.tableDataList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
  },
}
</script>


<style scoped lang="scss">
.title {
  display: flex;
  align-items: center;
  padding: 16px 0 0;
  font-weight: bold;
  font-size: 16px;
  margin-bottom:15px;
  position: relative;

  .icon {
    font-size: 12px;
    font-weight: 400;
    color: #3070ff;
    margin-left: 10px;
  }
  .time {
    position: absolute;
    right: 0px;
    top: 10px;
    color: #8C8C8C;
    font-size: 12px;
    font-weight: 400;
  }
}

.timeType {
  display: flex;
  align-items: center;
  margin-right: 10px;

  li {
    border: 1px solid #eee;
    height: 32px;
    margin: 0;
    padding: 0 15px;
    list-style: none;
    cursor: pointer;

    &.active {
      border-color: #2d8cf0;
      color: #2d8cf0;
    }
  }
}

.time-big {
  display: flex;
  align-items: center;
}
.formGroup {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  width: 100%;
}
.center-title {
  height: 30px;
  display: flex;
  align-items: center;
  span {
    content: "";
    width: 4px;
    height: 14px;
    background-color: #3070ff;
    display: block;
    margin-right: 5px;
  }
}

.tableAnalysis {
  padding-bottom: 20px;
  position: relative;
  .center-title {
    margin-bottom: 20px;
  }
  .exportData {
    position: absolute;
    right: 0px;
    top: 0px;

  }
}
</style>
